package day20170427.kaoshi;

import java.io.FileWriter;

import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

public class Common {
	public final static String FILE = "src/main/java/day20170427/kaoshi/student.xml";
	
	/**
     * 通过document对象将内存中的dom树保存到新的xml文档。
     * @param document
     * @throws Exception
     */
    public static void writeXMLDocument(Document document) throws Exception {
    	//设置XML文档输出格式
    	OutputFormat format = OutputFormat.createPrettyPrint(); 
    	//设置是否缩进
        format.setIndent(true); 
        //以空格方式实现缩进
        format.setIndent("   "); 
        //设置是否换行
        format.setNewlines(true); 
        //进行更新xml
        XMLWriter writer = new XMLWriter(new FileWriter(Common.FILE),format);
        writer.write(document);
        writer.close();
    }
}
